Page({

  /**
   * 页面的初始数据
   */
  data: {
    age: ['1周', '2周', '3周', '1月', '2月', '3月', '4月', '5月', '6月', '7月',
      '8月', '9月', '10月', '11月', '1岁', '2岁', '3岁', '4岁', '5岁', '6岁', '7岁', '8岁', '9岁', '10岁', '11岁', '12岁', '13岁', '14岁', '15岁', '16岁'],
    hint: '去挑品种'
  },
  openid: "",
  onLoad: function (opt) {
  },

  onShow:function(){
    if(wx.getStorageSync("term")){
      this.setData({hint:wx.getStorageSync("term")})
    }
  },
  bindViewTap: function () {
    wx.switchTab({
      url: '../index/index'
    })
  },
  radiochange: function (e) {
    this.setData({ gender: e.detail.value })
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  pickType:function(e){
    wx.setStorageSync("petType", e.currentTarget.dataset.type)
  },
  toPick: function () {
    wx.navigateTo({
      url: "/pages/pick/pick?type="+wx.getStorageSync("petType")+"&path=load"
    })
  },

  showToast: function (str) {
    wx.showToast({
      title: str,
      icon: "none"
    })
  },

// 将字符月份转化为表示天数的整型
  convertDays: function(str){
    var num = parseInt(str.slice(0,str.length-1))
    var date = str.slice(-1)
    var base = 0
    if(date=="周"){
      base = 7
    }
    else if(date=="月"){
      base = 30
    }
    else{
      base = 365
    }
    return num*base
  },

  submit: function (e) {
    var v = e.detail.value
    
    if(v.name == "") {
      this.showToast("宠物名字" + "必填哦！")
    }
    else if (v.pet == "") {
      this.showToast("宠物类型" + "必填哦！")
    }
    else if (v.gender == "") {
      this.showToast("性别" + "必填哦！")
    }
    else if (v.age == null) {
      this.showToast("年龄" + "必填哦！")
    }
    
    else {
      v["term"] = wx.getStorageSync("term")
      v["age"] = this.convertDays(v["age"])
      wx.setStorageSync("form", v)
      wx.navigateTo({
        url: "/pages/time/time"
      })
    }

  },
})